package net.expectx.micro.shop.api.controller;

import io.swagger.annotations.Api;
import net.expectx.micro.shop.api.common.ApiConstants;
import net.expectx.micro.shop.api.common.ApiResult;
import net.expectx.micro.shop.dao.bean.ContentAdvertisingActivities;
import net.expectx.micro.shop.dao.bean.ContentAdvertisingActivitiesExample;
import net.expectx.micro.shop.dao.bean.ProductProduct;
import net.expectx.micro.shop.dao.bean.ProductProductExample;
import net.expectx.micro.shop.rpc.api.ContentAdvertisingActivitiesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author hxs
 */
@Api(value = "活动公告", description = "活动公告接口")
@Controller
@RequestMapping("content/advertising/activities")
public class ContentAdvertisingActivitiesController {
    @Autowired
    ContentAdvertisingActivitiesService contentAdvertisingActivitiesService;

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public ResponseEntity<ApiResult> page() {
        Map<String, Object> result = new HashMap<>(16);
        ContentAdvertisingActivitiesExample contentAdvertisingActivitiesExample = new ContentAdvertisingActivitiesExample();
        /**
         * 创造条件
         */
        ContentAdvertisingActivitiesExample.Criteria criteria = contentAdvertisingActivitiesExample.createCriteria();
        criteria.andIsDeletedEqualTo(ApiConstants.NO);

        /**
         * 排序
         */
        contentAdvertisingActivitiesExample.setOrderByClause("gmt_modified desc");

        List<ContentAdvertisingActivities> contentAdvertisingActivities = contentAdvertisingActivitiesService.selectByExample(contentAdvertisingActivitiesExample);

        long total = contentAdvertisingActivitiesService.countByExample(contentAdvertisingActivitiesExample);

        result.put("count", total);
        result.put("msg", "");
        result.put("data", contentAdvertisingActivities);
        return new ResponseEntity<>(new ApiResult(true,200,null,result), HttpStatus.OK);
    }
}
